package com.bangdream.michelia.view.activity.currency.personal;

import android.view.View;
import android.widget.EditText;

import com.bangdream.michelia.R;
import com.bangdream.michelia.contract.UserContract;
import com.bangdream.michelia.entity.UserMsgBean;
import com.bangdream.michelia.presenter.UserPresenter;
import com.bangdream.michelia.presenter.base.BasePresenter;
import com.bangdream.michelia.utils.PublicUtil;
import com.bangdream.michelia.view.activity.base.SwipeBackActivity;

/**
 * Created by Administrator on 2017/1/12.
 * 修改用户数据
 */

public class ModifyUserData extends SwipeBackActivity<UserContract.IUserEditView, UserPresenter<UserContract.IUserEditView>> implements View.OnClickListener, UserContract.IUserEditView  {
    private static final String TAG = "ModifyUserData";
    private ModifyType type;
    private EditText editText;
    private String data;


    public enum ModifyType {
        NameType, MobileType, EmailType, HeadSmallType,PwdType,PositionType,CityType,SexType;
    }

    @Override
    public int getLayout() {
        return R.layout.modify_user_data;
    }

    @Override
    public void findId() {
        editText = findViewById(R.id.editText);
    }

    @Override
    public void setListener() {

    }

    @Override
    public void logic() {
        initTitleBar(" ", "修改个人信息", "完成", this);

        if (getIntent().getExtras() != null) {
            type = (ModifyType) getIntent().getExtras().getSerializable("type");
        }
        if (type != null) {
            if (type.equals(ModifyType.PositionType)) {
                tv_title.setText("修改职位");
                editText.setHint("请输入您的职位");
            } else if (type.equals(ModifyType.PwdType)) {
                tv_title.setText("修改密码");
                editText.setHint("请输入您的新密码");
            } else if (type.equals(ModifyType.NameType)) {
                tv_title.setText("修改昵称");
                editText.setHint("请输入您的昵称");
            } else if (type.equals(ModifyType.SexType)) {
                tv_title.setText("修改性别");
                editText.setHint("请输入您的性别");
            }
        }
    }

    @Override
    public UserPresenter<UserContract.IUserEditView> createPresenter() {
        return new UserPresenter<>();
    }

    //nickname	昵称	string
    //sex	性别(性别 F女 M男)	string
    //telphone	电话号码	string
    //userId	用户ID	string
    //username	用户名	string
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_left:
                finish();
                break;
            case R.id.tv_right:
                if (type == null || editText.getText().toString().isEmpty())
                    return;
                String editMsg = editText.getText().toString();
                if (type.equals(ModifyType.MobileType)) {

                } else if (type.equals(ModifyType.EmailType)) {
                    if (PublicUtil.isEmailNO(editText.getText().toString())) {

                    } else {
                        showText("邮箱格式不正确");
                    }
                }else if(type.equals(ModifyType.NameType)){
//                    mPresenter.editUser("nickname",editMsg,pd);
                }else if(type.equals(ModifyType.SexType)){
                    String sex = editMsg.equals("女") ? "F" : "M";
//                    mPresenter.editUser("sex",sex,pd);
                }
                break;
            default:
                break;
        }
    }

    @Override
    public void isSuccessed(boolean isSuccess) {
        showText("修改成功");
        finish();
    }
}
